import { Effect, Reducer } from 'umi';

export interface CourseModelState {
  courses: any[];
}

export interface CourseModelType {
  namespace: 'courses';
  state: CourseModelState;
  effects: {
    saveCourses: Effect;
  };
  reducers: {
    save: Reducer<CourseModelState>;
  };
}

const Model: CourseModelType = {
  namespace: 'courses',

  state: {
    courses: [],
  },

  effects: {
    *saveCourses({ payload }, { put }) {
      yield put({
        type: 'save',
        payload,
      });
    },
  },

  reducers: {
    save(state, action) {
      return {
        ...state,
        courses: action.payload,
      };
    },
  },
};

export default Model;